package com.github.leecho.spring.cloud.gateway.dubbo.client;

import com.github.leecho.spring.cloud.gateway.dubbo.route.DubboRoute;
import com.github.leecho.spring.cloud.gateway.dubbo.route.DubboRoute.DubboProvider;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.rpc.service.GenericService;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author LIQIU
 * @date 2021/7/27 17:14
 */
public class DefaultDubboGenericServiceCache implements DubboGenericServiceCache {

	private final ConcurrentHashMap<String,ReferenceBean<GenericService>> cache = new ConcurrentHashMap<>();

	@Override
	public ReferenceBean<GenericService> get(DubboProvider dubboProvider) {
		return cache.get(dubboProvider.toString());
	}

	@Override
	public ReferenceBean<GenericService> put(DubboProvider dubboProvider, ReferenceBean<GenericService> referenceBean) {
		return cache.putIfAbsent(dubboProvider.toString(),referenceBean);
	}
}
